# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1422
# Description:  反序列化
# Author:       yzl
# Date:         2019-02-10
#-------------------------------------------------------------------------------


import json

# 产品类
class Product:
    def __init__(self,d):
        self.__dict__ = d

def json2Product(d):
    return Product(d)

f = open('files/products.json','r',encoding='utf-8')
jsonstr = f.read()
f.close()

product = json.loads(jsonstr,object_hook=Product)
print(type(product[0]))
print(product[0].name)

print('-------------------------')

product2 = json.loads(jsonstr,object_hook=json2Product)
print(type(product2[0]))
# print(product2[0]['name'])
print(product2[0].name)

